<template>
  <div class="app-container">
    <!-- Header 区域 -->
    <cart-header></cart-header>

    <!-- 商品 Item 项组件 -->
    <cart-item v-for="item in cartList" :key="item.id" :item="item"></cart-item>

    <!-- Footer 区域 -->
    <cart-footer></cart-footer>
  </div>
</template>

<script setup>
import CartHeader from '@/components/cart-header.vue'
import CartFooter from '@/components/cart-footer.vue'
import CartItem from '@/components/cart-item.vue'
import {onMounted, computed} from "vue";
import {useStore} from "vuex";

const $store = useStore();

onMounted(() => {
  $store.dispatch('cart/getCartList');
});

// 使用 computed 映射 cartList 状态
const cartList = computed(() => $store.state.cart.cartList);
</script>

<script>
export default {
  name: 'App'
}
</script>

<style lang="less" scoped>
.app-container {
  padding: 50px 0;
  font-size: 14px;
}
</style>
